﻿@using FwProject.PrePaymentInfo.Dto
@using FwProject.PrePaymentInfo
@using X.PagedList
@model IPagedList<PrePaymentInfoOutputDto>
@{
    ViewBag.Title = "退回预收款";
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    @if (IsGranted(FwProject.Authorization.PermissionNames.Finance_Operation_ReturnAdvance))
                    {
                        <button class="btn btn-primary btn-xs" onclick="top.window.openTab(1119,'预收单','@Url.Action("CreateRefundPayment")')"><i class="fa fa-plus"></i>退还预收款</button>
                    }
                    else
                    {
                        <button type="button" class="btn btn-default btn-xs">无退还预收款权限</button>
                    }
                </div>
            </div>
            <div class="ibox-content">
                <div class="row m-b-sm m-t-sm">
                    <form class="form-horizontal" asp-controller="Settlement" asp-action="RefundPayment" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Get" data-ajax-mode="replace">
                        <input type="hidden" id="size" name="size" value="0" />
                        @*<div class="col-md-5">
                            <div class="input-group">
                                <input type="text" name="keyword" placeholder="关键词" class="input-sm form-control"> <span class="input-group-btn">
                                    <button type="submit" class="btn btn-sm btn-primary"> 搜索</button>
                                </span>
                            </div>
                        </div>*@
                        <div class="col-md-2 col-lg-2">
                            <label class="control-label col-md-5 col-lg-4">单号：</label>
                            <div class="input-group">
                                <input type="text" name="keyword" id="keyword" class="input-sm form-control" autocomplete="off">
                            </div>
                        </div>
                        <div class="col-md-2 col-lg-2">
                            <label class="control-label col-md-5 col-lg-5">状态：</label>
                            <div class="input-group">
                                <select class="form-control" name="PrePaymentInfoStatus" id="PrePaymentInfoStatus">
                                    <option value="" selected="selected">全部</option>
                                    <option value="0">未提交</option>
                                    <option value="1">已提交</option>
                                    <option value="2">已审核</option>
                                    <option value="3">退回</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-1">
                            <span class="input-group-btn">
                                <button type="submit" class="btn btn-sm btn-primary"> 查询</button>
                            </span>
                        </div>
                    </form>
                </div>
                <div id="data_list">
                    @{Html.RenderPartial("RefundPaymentPartial", Model);}
                </div>
            </div>
        </div>
    </div>
</div>
<div id="modal_ajax" class="modal inmodal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
</div>
<div id="modal_del" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated fadeIn">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">删除</h4>
            </div>
            <form action="" method="post" novalidate="novalidate" data-ajax="true" data-ajax-success="DeletAjaxCallback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" role="form">
                @Html.AntiForgeryToken()
                <div class="modal-body">
                    <p>确定要删除？</p>
                    @*<input type="hidden" name="id" value="" />*@
                </div>
                <div class="modal-footer">
                    <button type="reset" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="btn_del_sure" type="submit" class="btn btn-danger" data-loading-text="执行中...">确定</button>
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/js/PrintUtil.js"></script>
    <script type="text/javascript">
        function Print() {
            printGirdObj({
                containerId: 'table_print',//包含表格容器のID
                title: '@ViewBag.Title',
                showRowNum: false,  //表格中rownumbers: true时为true
                showOrder: false,//是否显示序号，rownumbers: true时有效，默认false
                printInit: { //打印初始化设置参数
                    portrait: false //true纵向,false横向
                }
            });
        }

        function Export() {
            var keyword = $('#keyword').val();
            window.location.href = "/Settlement/ExportRefundPayment?keyword=" + keyword;
        }


        //layer.msg("test",{time:2000});
        $(document).ready(function () {
            $('#modal_ajax').on('show.bs.modal', function (e) {
                $(this).addClass('loading');
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                    $(this).load(url, function () {
                        $.validator.unobtrusive.parse(this); //$("#form_model_create").validate();
                        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        //绑定餐厅
                        $.getJSON("/Restaurant/GetSuggestData").done(function (data) {
                            CommonAjaxCallback(data, function () {
                                bindSuggest(data.result);
                            }, null);
                        }).fail(function () {
                            layer.msg('连接超时，获取餐厅信息失败！', {
                                icon: 2,
                                time: 2000
                            });
                        });

                        //绑定经办人
                        $.getJSON("/Users/GetSuggestData2").done(function (data) {
                            CommonAjaxCallback(data, function () {
                                bindUserSuggest(data.result);
                            }, null);
                        }).fail(function () {
                            layer.msg('连接超时，获取经办人信息失败！', {
                                icon: 2,
                                time: 2000
                            });
                        });


                    });
                }
            });
            $('#modal_ajax').on('hidden.bs.modal', function (e) {
                $(this).empty();
            });

            $('#modal_del,#modal_password_reset').on('show.bs.modal', function (e) {
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url)
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                $(this).find("form").attr("action", url);
            });
            $('#modal_del,#modal_password_reset').on('hidden.bs.modal', function (e) {
                $(this).find("form").attr("action", "");
            });
        });

        function bindSuggest(data) {
            if ($("#RestaurantInfoId") != undefined) {
                $("#RestaurantInfoId").bsSuggest({
                    effectiveFields: ["restaurantName"],
                    effectiveFieldsAlias: { "restaurantName": "名称" },
                    searchFields: ["restaurantName"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "restaurantName",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $("#RestaurantInfoName").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }

        function bindUserSuggest(data) {
            if ($("#AgentPeoper") != undefined) {
                $("#AgentPeoper").bsSuggest({
                    effectiveFields: ["name", "mobile"],
                    effectiveFieldsAlias: { "name": "姓名", "mobile": "电话" },
                    searchFields: ["name"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "name",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $("#AgentPeoperUserId").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }

            function ReloadAjaxCallbackgoback(data, successInfo) {
                CommonAjaxCallback(data, function () {
                    $('#modal_ajax').modal("hide");
                    window.location.reload();
                }, successInfo);
            }

            function DeletAjaxCallback(data, successInfo) {
                CommonAjaxCallback(data, function () {
                    $("#modal_del").modal("hide");
                    $($button).parent().parent().remove();
                    window.location.reload();
                }, successInfo);
            }

            $("#data_list").on("change", "#pageSize", function () {
                var size = $("option:selected", this).val();
                var pageurl = $("#pageurl").val();
                $("#data_list").load("/Settlement/RefundPayment?size=" + size + "&r=" + Math.random() + pageurl, function () {
                    layer.closeAll();
                    $("#size").val($("option:selected", this).val());
                });
            });
    </script>
}
